package com.yc.chaoshi.cs_manage.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yc.chaoshi.cs_manage.service.IOmsOrderService;
import com.yc.chaoshi.entity.UmsAddres;
import com.yc.common.api.CommonResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author
 * @since 2022-08-04
 */
@RestController
@RequestMapping("/omsOrder")
public class OmsOrderController {

    @Resource
    IOmsOrderService omsOrderService;

    /**
     * 获得所有订单
     * @param pageNum
     * @param pageSize
     * @param sreachname
     * @param orderstatus
     * @return
     */
    @PostMapping("/list")
    public CommonResult list(@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                             @RequestParam(value = "pageSize",defaultValue = "5") Integer pageSize,
                             @RequestParam(value = "sreachname") String sreachname,
                             @RequestParam(value = "orderstatus",defaultValue = "") Integer orderstatus) {
        Page page = omsOrderService.listAll(pageNum,pageSize,sreachname,orderstatus);
        return CommonResult.success(page);
    }


    /**
     * 修改管理员
     * @param id
     * @return
     */
    @GetMapping("/delete/{id}")
    public CommonResult delete(@PathVariable Integer id){
        boolean result=this.omsOrderService.delete(id);
        if (result){
            return CommonResult.success(result);
        }else {
            return CommonResult.failed();
        }
    }
    @GetMapping("/getaddress/{addressid}")
    public CommonResult getaddress(@PathVariable Integer addressid){
        UmsAddres umsAddres=omsOrderService.getaddress(addressid);
        return CommonResult.success(umsAddres);
    }

    /**
     * 查询该订单的所有商品
     * @param pageNum
     * @param pageSize
     * @param sreachname
     * @param orderid
     * @return
     */
    @PostMapping("listGoods")
    public CommonResult listGoods(@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                                  @RequestParam(value = "pageSize",defaultValue = "5") Integer pageSize,
                                  @RequestParam(value = "sreachname") String sreachname,
                                  @RequestParam(value = "orderid",defaultValue = "") Integer orderid){
        Page page = omsOrderService.listGoods(pageNum,pageSize,sreachname,orderid);
        return CommonResult.success(page);
    }

}

